package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import util.DBUtil;
import bean.Detection;

public class jiancedeo {
	
	public String pur_status;
	public String draunght_status;

	public ArrayList<Detection> getDetectionList(String sql) throws SQLException {
		Connection conn = DBUtil.open();
		Statement stmt = conn.createStatement();
		ResultSet rs = null;
		ArrayList<Detection> list = new ArrayList<Detection>();

		NumberFormat precent = NumberFormat.getPercentInstance();
		precent.setMinimumFractionDigits(0);
		// ��д�ٷ���

		try {
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
				String outlet_name=rs.getString(1);
				String draunght_status=st(rs.getString(2));
				String pur_status=st(rs.getString(3));
				String oil_con=rs.getString(4);
				String unite=rs.getString(5);
				String humidity=rs.getString(6);
				String temperature=rs.getString(7);
				String pressure=rs.getString(8);
				String company_name=rs.getString(9);
				String mon_date=rs.getString(10);
				String data=time.format(time.parse(mon_date));
				Detection dec = new Detection();
				dec.setCompany_name(company_name);
				dec.setDraunght_status(draunght_status);
				dec.setHumidity(humidity);
				dec.setMon_date(data);
				dec.setOil_con(oil_con);
				dec.setOutlet_name(outlet_name);
				dec.setPressure(pressure);
				dec.setPur_status(pur_status);
				dec.setTemperature(temperature);
				dec.setUnite(unite);
				
				list.add(dec);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}finally {
			DBUtil.close();
	    }
		return list;
	}
	
	public String st(String stu){
		if( stu.equals("1")){
			stu="开启";
			return stu;
		}
		else{
			stu="关闭";
			return stu;
		}
	}
	
}
